<?php

namespace Liuhelong\LaravelAdmin\Wechat\Http\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \Liuhelong\LaravelAdmin\Wechat\Models\WechatOffiaccountTemplateMessage;
use Illuminate\Support\Str;

class WechatOffiaccountTemplateMessageController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '模板消息';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new WechatOffiaccountTemplateMessage());

        $grid->column('template_id', __('laravel_admin_wechat.Template id'));
        $grid->column('title', __('laravel_admin_wechat.Title'));
        $grid->column('primary_industry',__('laravel_admin_wechat.Primary industry'));
        $grid->column('deputy_industry',__('laravel_admin_wechat.Deputy industry') );
        $grid->column('content',__('laravel_admin_wechat.Content') )->display(function($content){
			return (string)Str::of($content)->replaceMatches('/\\n/', '<br>');
		})->width(300);
		
        $grid->column('example',__('laravel_admin_wechat.Example') )->display(function($content){
			return (string)Str::of($content)->replaceMatches('/\n/', '<br>');
		})->width(500);
		
		$grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
            $actions->disableEdit();
			
			//$actions->add(new \Liuhelong\LaravelAdmin\Wechat\Http\Actions\WechatOffiaccountUser\Remark);
        });
		
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(WechatOffiaccountTemplateMessage::findOrFail($id));



        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new WechatOffiaccountTemplateMessage());
		$form->text('shortId','模板编号')->help('模板库中模板的编号，有“TM**”和“OPENTMTM**”等形式');


        return $form;
    }
}
